<?php
class C_flow extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_flow');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
				$this->load->view('v_flow');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['flow_name'] = nosql_post("flow_name");
		$data['flow_code'] = nosql_post("flow_code");
		$data['flow_subcode'] = nosql_post("flow_subcode");
		echo $this->m_flow->_list($data);
	}
	
	function _insert(){
		$data = array(
			'flow_name' => $this->input->post('flow_name'), 
			'flow_code' => $this->input->post('flow_code'), 
			'flow_subcode' => $this->input->post('flow_subcode'), 
			  
			'flow_active'=> 'y',
			'flow_insert_user'	=>$_SESSION[SESSION_USERNAMA],
			'flow_insert_date'=> date("Y-m-d h:i:s")
		);
		$this->m_flow->_insert($data);
		echo 1;
	}
	
	function _update(){
		$flow_id = $this->input->post('flow_id');
		$flowdiv_id = $this->input->post('flowdiv_id');
		$data = array(
			'flow_name' => $this->input->post('flow_name'), 
			'flow_code' => $this->input->post('flow_code'), 
			'flow_subcode' => $this->input->post('flow_subcode'), 
			
			'flow_update_user'	=>$_SESSION[SESSION_USERNAMA],
			'flow_update_date'=> date("Y-m-d h:i:s")
		);
		$this->m_flow->_update($data,$flow_id,$flowdiv_id);
		echo 1;
 	}
	
	function _delete(){
		$flow_id= $this->input->post('flow_id');
		$data = array(
			'flow_active' => 'n'
		);
		$this->m_flow->_delete($data,$flow_id);
		echo 1;
	}
}